package com.ssps.back.platform.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssps.back.platform.service.UserInfoService;
import com.ssps.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author li
 * @time 2020/07/22 19:28:36
 */

@Controller
@RequestMapping("userInfo")
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;

    @RequestMapping("userInfoList")
    public String userList( ){
        return "userInfo/userInfoList";
    }


    /**
     *
     * 展示所有信息
     */

    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> userList(@RequestParam(name = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(name = "pageSize",defaultValue = "5") Integer pageSize , String status, String uname) {
        Map<String,Object> map = new HashMap<String,Object>();
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<UserInfo> userInfoList= userInfoService.findAll(status,uname);
            PageInfo<UserInfo> pageInfo = new PageInfo<UserInfo>(userInfoList);
            map.put("pageInfo",pageInfo);
            map.put("userInfoList",userInfoList);
            map.put("result", true);
        }catch(Exception e) {
            map.put("result", false);
            e.printStackTrace();
        }
        return map;
    }



    /*
    *
    * 身份证信息读取验证并添加
    * */
    @ResponseBody
    @RequestMapping("updateAudit")
    public Map<String,Object> userInfoAudit(Integer uiid){
        Map<String,Object> map=new HashMap<>();
        try{
            userInfoService.userInfoSave(uiid);
            map.put("result",true);
        }catch (Exception e){
            e.printStackTrace();
            map.put("result",false);
        }
        return map;
    }



    /*
     *
     * 身份证信息不符合驳回信息
     * */
    @ResponseBody
    @RequestMapping("turnDown")
    public Map<String,Object> userInfoDown(UserInfo userInfo){
        Map<String,Object> map=new HashMap<>();
        try{
            userInfoService.userInfoUpdate(userInfo);
            map.put("result",true);
        }catch (Exception e){
            e.printStackTrace();
            map.put("result",false);
        }
        return map;
    }




}
